const Qs = require('qs')
module.exports={
  //传入url地址返回参数json
  hrefParamsToJson(url){
    let getLocationHref=window.location.href
    const number = getLocationHref.lastIndexOf("?");
    const s = getLocationHref.substring(number+1);
    return Qs.parse(s)
  },
  getPageUrlParams() {
    let getLocationHref=window.location.href
    const number = getLocationHref.lastIndexOf("?");
    const s = getLocationHref.substring(number+1);
    let urlData= Qs.parse(s)
    if(urlData.params){
      return JSON.parse(urlData.params)
    }else{
      return {}
    }
  },
  initLocalStorage(that){
    console.log(this.getUrlParamsToObject(),"this.$dataDillUtil.getPageUrlParams()");
    let {businessId,shopId} = this.getUrlParamsToObject();
    if(businessId){
      localStorage.setItem("businessId",businessId)
    }
    if(shopId){
      localStorage.setItem("shopId",shopId)
      this.schoolListReq(that)
    }
  },
  //获取学校列表
  schoolListReq(that){
    that.$khReqMethod({url: "/payscancode/h5/school/"+localStorage.getItem("shopId"), method: 'get', isLoading: false, isParams: true}).then(res => {
      if (res.code === 0) {
        let reqData=res.data;
        //设置了学校的名称
        document.title=reqData.name
        localStorage.setItem("shopName",reqData.name)
      }
    })
  },
  getUrlParamsToObject(){
    let getLocationHref=window.location.href
    const number = getLocationHref.lastIndexOf("?");
    const s = getLocationHref.substring(number+1);
    return Qs.parse(s)
  },
  toPagesHtml(url, params) {
    window.location.href = `./${url}.html?businessId=${localStorage.getItem("businessId")}&params=${JSON.stringify(params)}`;
  },
  dillInfoToString(studentObjectInfo){
    let showString="";
    if(studentObjectInfo){
      Object.values(JSON.parse(studentObjectInfo)).forEach(value => {
        showString+=`${value} | `;
      })
      return showString.slice(0,-2);
    }else{
      return "";
    }
  },
  pageReload(){
    window.location.reload()
  },
  pageBack(){
    window.history.back()
  },
  historyGo(index){
    window.history.go(1)
  },
  androidKeyBoyListion(){
    var originalHeight=document.documentElement.clientHeight ||document.body.clientHeight;
    window.onresize=function(){
      //键盘弹起与隐藏都会引起窗口的高度发生变化
      var resizeHeight=document.documentElement.clientHeight || document.body.clientHeight;
      if(resizeHeight-0<originalHeight-0){
        //当软键盘弹起，在此处操作
      }else{
        window.scrollTo(0,0)   //页面滚动到顶部
        //当软键盘收起，在此处操作
      }
    }
  },
  iosKeyBoyListion(){
    document.body.addEventListener('focusin', () => {
      //软键盘弹出的事件处理

    })
    document.body.addEventListener('focusout', () => {
      //软键盘收起的事件处理
      window.scrollTo(0,0)
    })
  },
}
